<?php
	class DatabaseConnection
	{
    
		// Private members
		private $hostAddress = "";
		private $dbUser = "";
		private $dbPass = "";
		private $dbName = "";
		private $mySQLI = NULL;
    
		// Constructor 
		public function __construct($settings)
		{
			$this->hostAddress = $settings['host'];  
			$this->dbUser = $settings['dbUser'];
			$this->dbPass = $settings['dbPass'];
			$this->dbName = $settings['dbName'];  
		}
    
		public function Connect()
		{
			// Open db connection  
			$this->mySQLI = new mysqli($this->hostAddress, $this->dbUser, $this->dbPass, $this->dbName);
			if (!$this->mySQLI)
			{
					die("Connection to database failed");
					exit();
				}
				else
				{
					return true;
				}        
			}
    
		// Close db connection
		public function Close()
		{
			$this->mySQLI->close(); 
		}
    
		// Escape before db placement
		public function realEscapeString($string)
		{
			$this->mySQLI->real_escape_string($string) or die("Could not escape strings properly");
			return $string;
		}
    
		// Return prepare statement
		public function getPrepareStatement($sql)
		{
			$returnValue = $this->mySQLI->prepare($sql) or die("Couldnt prepare sql statement");
			return $returnValue;  
		}
    	
		// Direct query
		public function DirectQuery($sql)
		{
			$results = $this->mySQLI->query($sql);
			return $results; 
		}
		
		// Last insert id
		public function LastInsertId()
		{
			return mysqli_insert_id($this->mySQLI);
		}
	}
